package view;

import java.awt.Graphics;

import javax.swing.JLayeredPane;

import model.Element;
import model.Ticking;
import control.WrapperTicker;

public class Map extends JLayeredPane implements Ticking{
	
	private WrapperTicker wrappers = new WrapperTicker(this);
	private int speed = 9;
	
	private int dx;
	private int dy;
	
	public Map(int dx, int dy){
		setLayout(null);
		this.dx = dx;
		this.dy = dy;
	}
	
	public Map(){
		this(0, 0);
	}
	
	public void movement(int dx, int dy){
		if(this.dx+dx>=0&&this.dy+dy>=0){
			this.dx += dx;
			this.dy += dy;
		}
	}
	
	public void movement(char c){
    	if(c=='w'){
    		movement(0, -speed);
    	}else if(c=='s'){
    		movement(0,speed); 
    	}else if(c=='a'){
    		movement(-speed, 0);
    	}else if(c=='d'){
    		movement(speed,0);
    	}
	}
	
	public void forceMove(int dx, int dy){
		this.dx = dx;
		this.dy = dy;
	}
	
	public int getDX(){
		return dx;
	}
	public int getDY(){
		return dy;
	}
	
	public void tick() {
		this.updateUI();
		this.revalidate();
		wrappers.tick();
	}
	
	public void add(Element element){
		ElementWrapper ew = new ElementWrapper(element, this);
		wrappers.add(ew);
	}
}
